package com.qqtech.qquan.mall.controller;

import java.math.BigDecimal;
import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort.Direction;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.google.common.collect.Lists;
import com.qqtech.admin.context.AdminPage;
import com.qqtech.core.common.enums.YesNoEnum;
import com.qqtech.core.common.util.StringUtil;
import com.qqtech.core.common.util.TimeUtil;
import com.qqtech.core.frame.model.PageKit;
import com.qqtech.core.frame.model.PageOrder;
import com.qqtech.core.frame.model.Result;
import com.qqtech.core.frame.service.BaseService;
import com.qqtech.qquan.community.model.CommunityBaseQuery;
import com.qqtech.qquan.community.model.CommunityBaseVo;
import com.qqtech.qquan.community.service.CommunityBaseService;
import com.qqtech.qquan.mall.enums.MallShopAuditStatusDictEnum;
import com.qqtech.qquan.mall.enums.MallShopStyleDictEnum;
import com.qqtech.qquan.mall.enums.MallShopTypeDictEnum;
import com.qqtech.qquan.mall.model.MallShop;
import com.qqtech.qquan.mall.model.MallShopCategory;
import com.qqtech.qquan.mall.model.MallShopCategoryVo;
import com.qqtech.qquan.mall.model.MallShopQuery;
import com.qqtech.qquan.mall.model.MallShopVo;
import com.qqtech.qquan.mall.service.MallShopCategoryService;
import com.qqtech.qquan.mall.service.MallShopService;
import com.qqtech.qquan.order.enums.OrderBaseDeliveryStatusDictEnum;
import com.qqtech.qquan.order.enums.OrderBaseOrderStatusDictEnum;
import com.qqtech.qquan.order.enums.OrderBasePayStatusDictEnum;
import com.qqtech.qquan.order.enums.OrderBaseReturnPayStatusDictEnum;
import com.qqtech.qquan.order.model.OrderBaseQuery;
import com.qqtech.qquan.order.service.OrderBaseService;
import com.qqtech.qquan.sys.controller.BaseAdminController;
import com.qqtech.qquan.user.enums.UserAuthAuditStatusDictEnum;
import com.qqtech.qquan.user.model.UserAuthVo;
import com.qqtech.qquan.user.service.UserAuthService;

@Controller
@RequestMapping(value = "/mall/shop")
public class MallShopController extends BaseAdminController {
	@Resource
	private MallShopService mallShopService;
	@Resource
	private OrderBaseService orderBaseService;
	@Resource
	private CommunityBaseService communityBaseService;
	@Resource
	private MallShopCategoryService mallShopCategoryService;
	@Resource
	private UserAuthService userAuthService;

	@Override
	protected BaseService<MallShop> getBaseService() {
		return mallShopService;
	}

	@RequestMapping(value = "/list", method = RequestMethod.GET)
	public String list(Model model) {
		return "/mall/shop-list";
	}

	/**
	 * 圈圈商城详情
	 * @param model
	 * @return
	 */
	@RequestMapping(value = "/qqmallDetail", method = RequestMethod.GET)
	public String qqmallDetail(Model model) {
		Integer id = 1;
		MallShopVo mallShopVo = null;
		MallShopQuery query = new MallShopQuery();
		query.setId(id);
		Page<MallShopVo> page = mallShopService.queryPageListAdmin(query, null);
		if (page != null && page.getContent() != null && !page.getContent().isEmpty()) {
			mallShopVo = page.getContent().get(0);
		}
		if (mallShopVo != null) {
			if (mallShopVo.getCategoryName() != null && mallShopVo.getCategoryName().equals("其他")) {
				MallShopCategory mallShopCategory = mallShopCategoryService.getByCategoryId(mallShopVo.getCategoryId());
				MallShopCategory parentCategory = mallShopCategoryService
						.getByCategoryId(mallShopCategory.getParentId());
				if (parentCategory != null) {
					mallShopVo.setCategoryName(parentCategory.getName() + "-" + mallShopVo.getCategoryName());
				}
			}
		}
		model.addAttribute("mallShopVo", mallShopVo);
		if (mallShopVo != null) {
			OrderBaseQuery orderBaseQuery = new OrderBaseQuery();
			orderBaseQuery.setShopId(mallShopVo.getId());
			orderBaseQuery.setOrderStatus(OrderBaseOrderStatusDictEnum.UNCOMPLETED.getCode());// 未完成
			orderBaseQuery.setPayStatus(OrderBasePayStatusDictEnum.UNPAYED.getCode());// 未付款
			int waitPayCount = orderBaseService.queryCount(orderBaseQuery);// 待付款
			orderBaseQuery = new OrderBaseQuery();
			orderBaseQuery.setShopId(mallShopVo.getId());
			orderBaseQuery.setPayStatus(OrderBasePayStatusDictEnum.PAYED.getCode());// 已付款
			orderBaseQuery.setDeliveryStatus(OrderBaseDeliveryStatusDictEnum.UNSEND.getCode());// 未发货
			orderBaseQuery.setNotEqualReturnPayStatus(OrderBaseReturnPayStatusDictEnum.RETURNING.getCode());// 不等于退款中
			int waitSendCount = orderBaseService.queryCount(orderBaseQuery);// 待发货
			orderBaseQuery = new OrderBaseQuery();
			orderBaseQuery.setShopId(mallShopVo.getId());
			orderBaseQuery.setPayStatus(OrderBasePayStatusDictEnum.PAYED.getCode());// 已付款
			orderBaseQuery.setDeliveryStatus(OrderBaseDeliveryStatusDictEnum.SENDED.getCode());// 商家已发货
			orderBaseQuery.setNotEqualReturnPayStatus(OrderBaseReturnPayStatusDictEnum.RETURNING.getCode());// 不等于退款中
			int waitReceiptCount = orderBaseService.queryCount(orderBaseQuery);// 待收货
			orderBaseQuery = new OrderBaseQuery();
			orderBaseQuery.setShopId(mallShopVo.getId());
			orderBaseQuery.setPayStatus(OrderBasePayStatusDictEnum.PAYED.getCode());// 已付款
			orderBaseQuery.setReturnPayStatus(OrderBaseReturnPayStatusDictEnum.RETURNING.getCode());// 退款中
			int waitRefundCount = orderBaseService.queryCount(orderBaseQuery);// 申请退款
			orderBaseQuery = new OrderBaseQuery();
			orderBaseQuery.setShopId(mallShopVo.getId());
			orderBaseQuery.setOrderStatus(OrderBaseOrderStatusDictEnum.COMPLETED.getCode());// 完成
			int completedCount = orderBaseService.queryCount(orderBaseQuery);//
			orderBaseQuery = new OrderBaseQuery();
			orderBaseQuery.setShopId(mallShopVo.getId());
			orderBaseQuery.setOrderStatus(OrderBaseOrderStatusDictEnum.CANCEL.getCode());// 取消
			int cancelCount = orderBaseService.queryCount(orderBaseQuery);//
			orderBaseQuery = new OrderBaseQuery();
			orderBaseQuery.setShopId(mallShopVo.getId());
			int orderCount = orderBaseService.queryCount(orderBaseQuery);// 总订单
			model.addAttribute("orderInfo",
					"待付款:" + waitPayCount + " , 待发货:" + waitSendCount + " , 待收货:" + waitReceiptCount + " , 申请退款:"
							+ waitRefundCount + " , 已完成:" + completedCount + " , 已取消:" + cancelCount + " , 总共:"
							+ orderCount + "单");
		}
		return "/mall/shop-detail";
	}
	
	@RequestMapping(value = "/list", method = RequestMethod.POST)
	@ResponseBody
	public AdminPage list(MallShopQuery query, HttpServletRequest request, HttpServletResponse response) {
		AdminPage adminPage = new AdminPage();
		String rows = (String) request.getParameter("rows"); // 每页条数
		query.setSize(Integer.valueOf(rows));
		Pageable pageKit = new PageKit(query.getPage(), query.getSize(), new PageOrder(Direction.DESC, "id"));
		Page<MallShopVo> page = mallShopService.queryPageListAdmin(query, pageKit);
		adminPage.setRows(page.getContent());
		adminPage.setTotal(Integer.valueOf(page.getTotalElements() + ""));
		return adminPage;
	}
	
	@RequestMapping(value = "/list2", method = RequestMethod.GET)
	public String list2(Model model) {
		return "/mall/shop-list2";
	}

	@RequestMapping(value = "/list2", method = RequestMethod.POST)
	@ResponseBody
	public AdminPage list2(MallShopQuery query, HttpServletRequest request, HttpServletResponse response) {
		AdminPage adminPage = new AdminPage();
		String rows = (String) request.getParameter("rows"); // 每页条数
		query.setSize(Integer.valueOf(rows));
		query.setAuditStatus(MallShopAuditStatusDictEnum.PENDING.getCode());//待审核
		Pageable pageKit = new PageKit(query.getPage(), query.getSize(), new PageOrder(Direction.DESC, "id"));
		Page<MallShopVo> page = mallShopService.queryPageListAdmin(query, pageKit);
		adminPage.setRows(page.getContent());
		adminPage.setTotal(Integer.valueOf(page.getTotalElements() + ""));
		return adminPage;
	}

	@RequestMapping(value = "/detail/{id}", method = RequestMethod.GET)
	public String detail(@PathVariable Integer id, Model model) {
		MallShopVo mallShopVo = null;
		MallShopQuery query = new MallShopQuery();
		query.setId(id);
		Page<MallShopVo> page = mallShopService.queryPageListAdmin(query, null);
		if (page != null && page.getContent() != null && !page.getContent().isEmpty()) {
			mallShopVo = page.getContent().get(0);
		}
		if (mallShopVo != null) {
			if (mallShopVo.getCategoryName() != null && mallShopVo.getCategoryName().equals("其他")) {
				MallShopCategory mallShopCategory = mallShopCategoryService.getByCategoryId(mallShopVo.getCategoryId());
				MallShopCategory parentCategory = mallShopCategoryService
						.getByCategoryId(mallShopCategory.getParentId());
				if (parentCategory != null) {
					mallShopVo.setCategoryName(parentCategory.getName() + "-" + mallShopVo.getCategoryName());
				}
			}
		}
		model.addAttribute("mallShopVo", mallShopVo);
		if (mallShopVo != null) {
			OrderBaseQuery orderBaseQuery = new OrderBaseQuery();
			orderBaseQuery.setShopId(mallShopVo.getId());
			orderBaseQuery.setOrderStatus(OrderBaseOrderStatusDictEnum.UNCOMPLETED.getCode());// 未完成
			orderBaseQuery.setPayStatus(OrderBasePayStatusDictEnum.UNPAYED.getCode());// 未付款
			int waitPayCount = orderBaseService.queryCount(orderBaseQuery);// 待付款
			orderBaseQuery = new OrderBaseQuery();
			orderBaseQuery.setShopId(mallShopVo.getId());
			orderBaseQuery.setPayStatus(OrderBasePayStatusDictEnum.PAYED.getCode());// 已付款
			orderBaseQuery.setDeliveryStatus(OrderBaseDeliveryStatusDictEnum.UNSEND.getCode());// 未发货
			orderBaseQuery.setNotEqualReturnPayStatus(OrderBaseReturnPayStatusDictEnum.RETURNING.getCode());// 不等于退款中
			int waitSendCount = orderBaseService.queryCount(orderBaseQuery);// 待发货
			orderBaseQuery = new OrderBaseQuery();
			orderBaseQuery.setShopId(mallShopVo.getId());
			orderBaseQuery.setPayStatus(OrderBasePayStatusDictEnum.PAYED.getCode());// 已付款
			orderBaseQuery.setDeliveryStatus(OrderBaseDeliveryStatusDictEnum.SENDED.getCode());// 商家已发货
			orderBaseQuery.setNotEqualReturnPayStatus(OrderBaseReturnPayStatusDictEnum.RETURNING.getCode());// 不等于退款中
			int waitReceiptCount = orderBaseService.queryCount(orderBaseQuery);// 待收货
			orderBaseQuery = new OrderBaseQuery();
			orderBaseQuery.setShopId(mallShopVo.getId());
			orderBaseQuery.setPayStatus(OrderBasePayStatusDictEnum.PAYED.getCode());// 已付款
			orderBaseQuery.setReturnPayStatus(OrderBaseReturnPayStatusDictEnum.RETURNING.getCode());// 退款中
			int waitRefundCount = orderBaseService.queryCount(orderBaseQuery);// 申请退款
			orderBaseQuery = new OrderBaseQuery();
			orderBaseQuery.setShopId(mallShopVo.getId());
			orderBaseQuery.setOrderStatus(OrderBaseOrderStatusDictEnum.COMPLETED.getCode());// 完成
			int completedCount = orderBaseService.queryCount(orderBaseQuery);//
			orderBaseQuery = new OrderBaseQuery();
			orderBaseQuery.setShopId(mallShopVo.getId());
			orderBaseQuery.setOrderStatus(OrderBaseOrderStatusDictEnum.CANCEL.getCode());// 取消
			int cancelCount = orderBaseService.queryCount(orderBaseQuery);//
			orderBaseQuery = new OrderBaseQuery();
			orderBaseQuery.setShopId(mallShopVo.getId());
			int orderCount = orderBaseService.queryCount(orderBaseQuery);// 总订单
			model.addAttribute("orderInfo",
					"待付款:" + waitPayCount + " , 待发货:" + waitSendCount + " , 待收货:" + waitReceiptCount + " , 申请退款:"
							+ waitRefundCount + " , 已完成:" + completedCount + " , 已取消:" + cancelCount + " , 总共:"
							+ orderCount + "单");
		}
		return "/mall/shop-detail";
	}

	@RequestMapping(value = "/update/{id}", method = RequestMethod.GET)
	public String update(@PathVariable Integer id, HttpServletRequest request, HttpServletResponse response) {
		MallShopVo mallShopVo = mallShopService.getById(id);
		if (mallShopVo != null) {
			if (mallShopVo.getCommunityId() != null && mallShopVo.getCommunityId().intValue() != 0) {
				CommunityBaseVo community = communityBaseService.getById(mallShopVo.getCommunityId());
				if (community != null) {
					mallShopVo.setCommunityName(community.getName());
				}
			}
			if (mallShopVo.getCategoryId() != null) {
				MallShopCategoryVo shopCategoryVo = mallShopCategoryService.getByCategoryId(mallShopVo.getCategoryId());
				if (shopCategoryVo != null) {
					mallShopVo.setCategoryName(shopCategoryVo.getName());
				}
			}
		}

		request.setAttribute("mallShopVo", mallShopVo);
		return "/mall/shop-update";
	}

	@RequestMapping(value = "/update", method = RequestMethod.POST)
	@ResponseBody
	public Result doUpdate(MallShopVo mallShopVo) {
		Result ret = new Result();
		if (mallShopVo == null || mallShopVo.getId() == null) {
			ret.addErr("参数不能为空");
		} else {
			if (mallShopVo.getType().intValue() == MallShopTypeDictEnum.QQMALLSHOP.getCode()) {// 圈商
				if (mallShopVo.getRate().compareTo(new BigDecimal("1")) == 1) {
					ret.addErr("分账比例不能大于1");
				}
				if (mallShopVo.getRate().compareTo(BigDecimal.ZERO) == -1) {
					ret.addErr("分账比例不能小于0");
				}

				if (mallShopVo.getDeliveryValue().compareTo(BigDecimal.ZERO) == -1) {
					ret.addErr("起送金额不能小于0");
				}
				if (mallShopVo.getFreight().compareTo(BigDecimal.ZERO) == -1) {
					ret.addErr("配送费不能小于0");
				}

				if (mallShopVo.getQuanPayRate() == null) {
					mallShopVo.setQuanPayRate(BigDecimal.ZERO);
				}
				if (mallShopVo.getQqQuanPayRate() == null) {
					mallShopVo.setQqQuanPayRate(BigDecimal.ZERO);
				}
				if (mallShopVo.getQuanPayRate().compareTo(new BigDecimal("1")) == 1) {
					ret.addErr("商家圈币支付比例不能大于1");
				}
				if (mallShopVo.getQuanPayRate().compareTo(BigDecimal.ZERO) == -1) {
					ret.addErr("商家圈币支付比例不能小于0");
				}
				if (mallShopVo.getQqQuanPayRate().compareTo(new BigDecimal("1")) == 1) {
					ret.addErr("平台圈币支付比例不能大于1");
				}
				if (mallShopVo.getQqQuanPayRate().compareTo(BigDecimal.ZERO) == -1) {
					ret.addErr("平台圈币支付比例不能小于0");
				}
				if (mallShopVo.getQuanPayRate().add(mallShopVo.getQqQuanPayRate())
						.compareTo(new BigDecimal("1")) == 1) {
					ret.addErr("商家加上平台提供的圈币支付比例不能大于1");
				}

				if (mallShopVo.getCategoryId() == null || mallShopVo.getCategoryId().equals("")) {
					ret.addErr("主营类目不能为空");
				}
				if (mallShopVo.getSendDeliveryType() == null) {
					ret.addErr("配送类型不能为空");
				}
				if (mallShopVo.getStyle() != null
						&& mallShopVo.getStyle().intValue() == MallShopStyleDictEnum.LOCAL.getCode()
						&& StringUtil.isBlank(mallShopVo.getLicensePic())) {
					ret.addErr("社区店铺营业执照未上传");
				}
				if (mallShopVo.getSendDeliveryType() != null && mallShopVo.getStyle() != null
						&& mallShopVo.getStyle().intValue() == MallShopStyleDictEnum.VIRTUAL.getCode()
						&& mallShopVo.getSendDeliveryType().indexOf("3") > -1) {
					ret.addErr("邻里店不支持圈圈配送");
				}
				MallShopVo tmp = mallShopService.getById(mallShopVo.getId());
				if (mallShopVo.getStyle().intValue() == MallShopStyleDictEnum.VIRTUAL.getCode()
						&& tmp.getStyle() != MallShopStyleDictEnum.VIRTUAL.getCode()) {// 圈商改邻里店
					OrderBaseQuery orderBaseQuery = new OrderBaseQuery();
					orderBaseQuery.setShopId(mallShopVo.getId());
					orderBaseQuery.setOrderStatus(OrderBaseOrderStatusDictEnum.UNCOMPLETED.getCode());
					int count = orderBaseService.queryCount(orderBaseQuery);
					if (count > 0) {
						ret.addErr("该店铺还有订单未完成。");
					}
				}
			}
		}
		if (ret.checkForm()) {
			// 获取用户对应的供应商
			MallShop update = new MallShop();
			update.setId(mallShopVo.getId());
			update.setRate(mallShopVo.getRate());
			update.setDeliveryValue(mallShopVo.getDeliveryValue());
			update.setCategoryId(mallShopVo.getCategoryId());
			update.setFreight(mallShopVo.getFreight());
			update.setStyle(mallShopVo.getStyle());
			update.setLicensePic(mallShopVo.getLicensePic());
			update.setSendDeliveryType(mallShopVo.getSendDeliveryType());
			update.setQuanPayRate(mallShopVo.getQuanPayRate());
			update.setQqQuanPayRate(mallShopVo.getQqQuanPayRate());
			if(StringUtil.isNotBlank(mallShopVo.getExtCommunityIds()) && StringUtil.isNotBlank(mallShopVo.getExtCommunityNames())){
				update.setExtCommunityIds(mallShopVo.getExtCommunityIds());
				update.setExtCommunityNames(mallShopVo.getExtCommunityNames());
			}
			update.setPhone(mallShopVo.getPhone());
			mallShopService.updateById(update);
		}
		return ret;
	}

	/**
	 * 审核通过
	 * 
	 * @param vo
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping(value = "/auditNormal", method = RequestMethod.POST)
	@ResponseBody
	public Result auditNormal(@RequestBody MallShopVo vo, HttpServletRequest request, HttpServletResponse response) {
		Result ret = new Result();
		MallShopVo entity = null;
		if (vo == null) {
			ret.addErr("参数不能为空");
		} else {
			if (vo.getId() == null) {
				ret.addErr("参数id不能为空");
			} else {
				entity = mallShopService.getById(vo.getId());
				if (entity == null) {
					ret.addErr("店铺不存在");
				} else if (entity.getAuditStatus().intValue() == MallShopAuditStatusDictEnum.NORMAL.getCode()) {
					ret.addErr("该店铺已经审核通过");
				} else {
					UserAuthVo userAuthVo = userAuthService.getByUserId(entity.getCreatorId());
					if (userAuthVo == null) {
						ret.addErr("该用户还没有提交身份认证");
					} else if (userAuthVo.getAuditStatus().intValue() != UserAuthAuditStatusDictEnum.THROUGH
							.getCode()) {
						ret.addErr("该用户身份认证还没审核通过");
					}
				}
			}
		}
		if (ret.checkForm()) {
			MallShop update = new MallShop();
			update.setId(vo.getId());
			update.setAuditStatus(MallShopAuditStatusDictEnum.NORMAL.getCode());
			update.setAuditAt(TimeUtil.now());
			mallShopService.updateById(update);
			vo.setAuditStatus(update.getAuditStatus());
			vo.setAuditAt(update.getAuditAt());
			ret.put("entity", vo);
		}
		return ret;
	}

	/**
	 * 不通过
	 * 
	 * @param vo
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping(value = "/auditNotpass", method = RequestMethod.POST)
	@ResponseBody
	public Result auditNotpass(@RequestBody MallShopVo vo, HttpServletRequest request, HttpServletResponse response) {
		Result ret = new Result();
		MallShopVo entity = null;
		if (vo == null) {
			ret.addErr("参数不能为空");
		} else {
			if (vo.getId() == null) {
				ret.addErr("参数id不能为空");
			} else {
				entity = mallShopService.getById(vo.getId());
				if (entity == null) {
					ret.addErr("店铺不存在");
				} else if (entity.getAuditStatus().intValue() == MallShopAuditStatusDictEnum.NOTPASS.getCode()) {
					ret.addErr("该店铺已经审核不通过");
				} else {
					UserAuthVo userAuthVo = userAuthService.getByUserId(entity.getCreatorId());
					if (userAuthVo == null) {
						ret.addErr("该用户还没有提交身份认证");
					} else if (userAuthVo.getAuditStatus().intValue() != UserAuthAuditStatusDictEnum.THROUGH
							.getCode()) {
						ret.addErr("该用户身份认证还没审核通过");
					}
				}
			}
		}
		if (ret.checkForm()) {
			MallShop update = new MallShop();
			update.setId(vo.getId());
			update.setAuditStatus(MallShopAuditStatusDictEnum.NOTPASS.getCode());
			update.setAuditAt(TimeUtil.now());
			mallShopService.updateById(update);
			vo.setAuditStatus(update.getAuditStatus());
			vo.setAuditAt(update.getAuditAt());
			ret.put("entity", vo);
		}
		return ret;
	}

	/**
	 * 更新hasRecommend
	 * 
	 * @param vo
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping(value = "/hasRecommend", method = RequestMethod.POST)
	@ResponseBody
	public Result hasRecommend(@RequestBody MallShopVo vo, HttpServletRequest request, HttpServletResponse response) {
		Result ret = new Result();
		MallShopVo entity = null;
		if (vo == null) {
			ret.addErr("参数不能为空");
		} else {
			if (vo.getId() == null) {
				ret.addErr("参数id不能为空");
			} else {
				entity = mallShopService.getById(vo.getId());
				if (entity == null) {
					ret.addErr("店铺不存在");
				} else {
					if (vo.getHasRecommend().intValue() == YesNoEnum.YES.getCode()) {
						if (entity.getStyle().intValue() == MallShopStyleDictEnum.VIRTUAL.getCode()) {
							MallShopQuery q = new MallShopQuery();
							q.setType(MallShopTypeDictEnum.QQMALLSHOP.getCode());
							q.setStyle(entity.getStyle());
							q.setHasRecommend(YesNoEnum.YES.getCode());
							if (mallShopService.queryCount(q) >= 6) {
								ret.addErr("邻里店铺首页只能推荐6个");
							}
						}
					}
				}
			}
		}
		if (ret.checkForm()) {
			MallShop update = new MallShop();
			update.setId(vo.getId());
			update.setHasRecommend(vo.getHasRecommend());
			mallShopService.updateById(update);
			ret.put("entity", vo);
		}
		return ret;
	}

	@RequestMapping(value = "/imgUpload", method = RequestMethod.GET)
	public String imgUpload(Model model) {
		return "/mall/shop-imgUpload";
	}

	/**
	 * 启用-圈币支付
	 * 
	 * @param id
	 * @return
	 */
	@RequestMapping(value = "/setUseQuanPay", method = RequestMethod.POST)
	@ResponseBody
	public Result setUseQuanPay(Integer id) {
		Result ret = new Result();
		MallShopVo shop = null;
		if (id == null) {
			ret.addErr("参数不能为空");
		} else {
			shop = mallShopService.getById(id);
			if (shop == null) {
				ret.addErr("店铺不存在");
			}
		}
		if (ret.checkForm()) {
			MallShop update = new MallShop();
			update.setId(id);
			update.setIsUseQuanPay(YesNoEnum.YES.getCode());
			mallShopService.updateById(update);
		}
		return ret;
	}

	/**
	 * 禁用-圈币支付
	 * 
	 * @param id
	 * @return
	 */
	@RequestMapping(value = "/setNoUseQuanPay", method = RequestMethod.POST)
	@ResponseBody
	public Result setNoUseQuanPay(Integer id) {
		Result ret = new Result();
		MallShopVo shop = null;
		if (id == null) {
			ret.addErr("参数不能为空");
		} else {
			shop = mallShopService.getById(id);
			if (shop == null) {
				ret.addErr("店铺不存在");
			}
		}
		if (ret.checkForm()) {
			MallShop update = new MallShop();
			update.setId(id);
			update.setIsUseQuanPay(YesNoEnum.NO.getCode());
			mallShopService.updateById(update);
		}
		return ret;
	}
	
	/**
	 * 后台根据社区查询店铺列表
	 * @param query
	 * @return
	 */
	@RequestMapping(value = "/getListByCommunity")
	@ResponseBody
	public Result getListByCommunity(MallShopQuery query) {
		Result ret = new Result();
		if(query.getCommunityId()==null){
			ret.put("list", Lists.newArrayList());
			return ret;
		}
		Pageable pageKit = new PageKit(1, Integer.MAX_VALUE, new PageOrder(Direction.DESC, "id"));
		List<MallShopVo> list = mallShopService.queryList(query, pageKit);
		ret.put("list", list);
		return ret;
	}
}
